﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ZeroBug.EasyFlow.Core;

namespace EasyFlow
{
    public partial class StepInfoViewModel : ObservableObject
    {
        private Cursor customCursor = null;
        [ObservableProperty]
        StepGroup _group;
        [ObservableProperty]
        string? _stepName;
        [ObservableProperty]
        string? _imagePath;
        public StepInfoViewModel(StepInfo stepInfo)
        {
            this.Group = stepInfo.Group;
            this.StepName = stepInfo.StepName;
            this.ImagePath = stepInfo.ImagePath;
        }
        [RelayCommand]
        void MouseDown(object obj)
        {
            ListBoxItem lbi = (ListBoxItem)obj;
            DataObject data = new DataObject(typeof(ListBoxItem), lbi);
            DragDrop.DoDragDrop(lbi, data, DragDropEffects.Copy);
        }
        [RelayCommand]
        void Feedback(object obj)
        {
            GiveFeedbackEventArgs e = (GiveFeedbackEventArgs)obj;
            if (e.Effects == DragDropEffects.Copy)
            {
                if (customCursor == null)
                    customCursor = CursorHelper.CreateCursor(e.Source as UIElement);

                if (customCursor != null)
                {
                    e.UseDefaultCursors = false;
                    Mouse.SetCursor(customCursor);
                }
            }
            else
                e.UseDefaultCursors = true;

            e.Handled = true;
        }
    }
}
